package com.share.finance.risk.third.web;

import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.common.utils.DbUtil;
import com.share.finance.risk.third.model.vo.ChannelLogPageReq;
import com.share.finance.risk.third.model.vo.InterfacePageReq;
import com.share.finance.risk.third.model.vo.ThirdLogPageReq;
import com.share.finance.risk.third.service.IChannelRequestLogService;
import com.share.finance.risk.third.service.IInterfaceConfigService;
import com.share.finance.risk.third.service.IThirdRequestLogService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Map;

@Slf4j
@RestController
public class ThirdLogController {
    @Autowired
    private IThirdRequestLogService thirdRequestLogService;
    @Autowired
    private IChannelRequestLogService channelRequestLogService;
    @Autowired
    private IInterfaceConfigService interfaceConfigService;
    @Autowired
    private DataSource dataSource;

    @ApiOperation("清理删除表中的数据,保留最近的n条")
    @ResponseBody
    @RequestMapping(value = "/common/deleteLog")
    public Result deleteLog(Integer retainNum) throws SQLException {
        final String[] tables = {"trd_channel_request_log", "trd_third_request_log"};
        Map<String, Object> reMap = DbUtil.deleteDataById(dataSource, tables, retainNum);
        return Result.success(reMap);
    }

    //分页查询
    @ResponseBody
    @RequestMapping(value = "/channelLog/pageList")
    public Result channelLogPageList(ChannelLogPageReq req) {
        Page page = channelRequestLogService.pageList(req);
        return Result.success(page);
    }

    //分页查询
    @ResponseBody
    @RequestMapping(value = "/thirdLog/pageList")
    public Result thirdLogPageList(ThirdLogPageReq req) {
        Page page = thirdRequestLogService.pageList(req);
        return Result.success(page);
    }

    //分页查询
    @ResponseBody
    @RequestMapping(value = "/interface/pageList")
    public Result interfacePageList(InterfacePageReq req) {
        Page page = interfaceConfigService.pageList(req);
        return Result.success(page);
    }
}
